import { defineStore } from 'pinia'
import { ref, reactive } from 'vue'
export const useStore = defineStore('x-driver', () => {
    //省市列表数据
    const provinceList = ref([])
    // 当前城市
    const currentCity = reactive({ name: '', code: '' })
    //城市列表菜单是否显示
    const city_menu_show = ref(false)
    // 驾考类型菜单是否显示
    const type_menu_show = ref(false)



    //驾考类型  小车 car  货车 truck  摩托车 moto 客车 bus ...
    const car_type_index = ref(0)


    ////////////////////////////////////////////////
    const set_provinceList = (provinces) => {
        provinceList.value = provinces
    }
    const set_current_city = (city) => {
        // 确保传入的是有效对象
        if (city && typeof city === 'object') {
            currentCity.name = city.name || '';
            currentCity.code = city.code || '';
        }
    }
    const set_city_menu_show = (boolean) => {
        city_menu_show.value = boolean
    }
    const set_type_menu_show = (boolean) => {
        type_menu_show.value = boolean
    }
    const set_car_type_index = (number) => {
        car_type_index.value = number
    }
    return {
        provinceList,
        currentCity,
        city_menu_show,
        type_menu_show,
        car_type_index,
        set_provinceList,
        set_current_city,
        set_city_menu_show,
        set_car_type_index,
        set_type_menu_show,

    }
},
    {
        persist: true,
    },
)